﻿using AutoMapper;
using BW.EatRabbit.API.Application.Commands;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers
{
    public class BasicInformationUpdateCommandHandler : IRequestHandler<BasicInformationUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<BasicInformation> basicinformationRepository;
        private readonly IMapper mapper;
        public BasicInformationUpdateCommandHandler(IBaseRepository<BasicInformation> basicinformationRepository, IMapper mapper)
        {
            this.basicinformationRepository = basicinformationRepository;
            this.mapper = mapper;

        }
        public Task<APIResult<int>> Handle(BasicInformationUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = ResultCode.更新成功;
            result.Message = ResultCode.更新成功.ToString();

       
            BasicInformation basic = mapper.Map<BasicInformation>(request);

            basic.Creator = request.UserNickname;
            basic.Updator = request.UserNickname;

            basicinformationRepository.UpdateEntity(basic);



            return Task.FromResult(result);
        }
    }
}
